package com.xxl.job.core.integration;

import com.xxl.job.core.executor.impl.XxlJobSolonExecutor;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.noear.solon.Solon;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;

/**
 * @author noear
 * @since 1.6
 */
public class XPluginImpl implements Plugin{

    @Override
    public void start(AppContext context) {
        //提取任务
        Solon.context().beanExtractorAdd(XxlJob.class, XxlJobSolonExecutor.instance);
        //容器加载完后，再启动任务
        context.lifecycle(Integer.MAX_VALUE, () -> XxlJobSolonExecutor.instance.start());
    }

    @Override
    public void stop() throws Throwable {
        XxlJobSolonExecutor.instance.destroy();
    }
}